﻿


using System;




namespace WCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            using (WCFClient.TeacherService.TeacherClient client = new TeacherService.TeacherClient("TeacherHttpEndpoint"))
            {
                var id = Guid.NewGuid();

                var name = client.GetTeacherNameWithId(id);
                Console.WriteLine(name);
                var teacher = client.GetTeacherWithId(id);

                var appid = Guid.NewGuid();
                var sessionid = Guid.NewGuid();
                var userid = Guid.NewGuid();
                var age = 0;
                var nameTea = "";
                Guid teacherid = Guid.NewGuid();
                client.GetTeacher(ref appid, ref sessionid, ref userid, ref age, ref nameTea, ref teacherid);

                //Console.Read();
            }

            Int32 i = 101;
            Console.WriteLine("请输入:c-->单调面试(PerCall)；s-->会话模式(PerSession)；e-->单例模式(PerSingle)");
            var s = System.Console.ReadLine();

            while (true)
            {
                switch(s)
                {
                    case "c":
                        StudentServicePerCall(i);
                        StudentServicePerCall(i);
                        StudentServicePerCall(i);
                        break;
                    case "s":
                        StudentServicePerSession(i);
                        StudentServicePerSession(i);
                        StudentServicePerSession(i);
                        break;
                    case "e":
                        StudentServicePerSingle(i);
                        StudentServicePerSingle(i);
                        StudentServicePerSingle(i);
                        break;
                    default:
                        StudentServicePerCall(i);
                        StudentServicePerCall(i);
                        StudentServicePerCall(i);
                        break;
                }
                Console.WriteLine("请按Ctrl + c 退出；否则继续。");
                ConsoleKeyInfo key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("请输入:c-->单调面试(PerCall)；s-->会话模式(PerSession)；e-->单例模式(PerSingle)");
                    s = System.Console.ReadLine();
                }
            }
            


        }

        private static void StudentServicePerCall(Int32 i)
        {
            using (WCFClient.StudentServicePerCall.StudentClient client = new StudentServicePerCall.StudentClient("StudentHttpEndpointCall"))
            {
                Console.WriteLine("StudentServicePerCall(PerCall): " + client.GetStudentName(i));
                System.Threading.Thread.Sleep(800);
                Console.WriteLine("StudentServicePerCall(PerCall): " + client.GetStudentName(i));
            }
        }

        private static void StudentServicePerSession(Int32 i)
        {
            using (WCFClient.StudentServicePerSession.StudentClient client = new StudentServicePerSession.StudentClient("StudentHttpEndpointSession"))
            {
                Console.WriteLine("StudentServicePerSession(PerSession): " + client.GetStudentName(i));
                System.Threading.Thread.Sleep(800);
                Console.WriteLine("StudentServicePerSession(PerSession): " + client.GetStudentName(i));
            }
        }

        private static void StudentServicePerSingle(Int32 i)
        {
            using (WCFClient.StudentServicePerSingle.StudentClient client = new StudentServicePerSingle.StudentClient("StudentHttpEndpointSingle"))
            {
                Console.WriteLine("StudentServicePerSingle(PerSingle): " + client.GetStudentName(i));
                System.Threading.Thread.Sleep(800);
                Console.WriteLine("StudentServicePerSingle(PerSingle): " + client.GetStudentName(i)); 
            }
        }
    }
}
